/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Define the types of keywords.
 *
 * <p>There are three kinds of keywords:<ul>
 * <li>Topics</li>
 * <li>Prerequisites</li>
 * <li>Other</li>
 * </ul></p>
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_contenttype")
@NamedQueries({@NamedQuery(name = "AssignmentKeywordType.findAll", query = "SELECT a FROM AssignmentKeywordType a"),
        @NamedQuery(name = "AssignmentKeywordType.findByAsgncntcd", query =
        "SELECT a FROM AssignmentKeywordType a WHERE a.keywordCode = :keywordCode"),
        @NamedQuery(name = "AssignmentKeywordType.findByDescription", query =
        "SELECT a FROM AssignmentKeywordType a WHERE a.description = :description")})
public class AssignmentKeywordType implements Serializable {
  private static final long serialVersionUID = 1L;

  /**
   * String representing the TOPIC keyword
   */
  public static final String TOPIC_CD = "TPC";
  /**
   * String representing the OTHER keyword
   */
  public static final String OTHER_CD = "OTH";
  /**
   * String representing the RPREREQUISITE keyword
   */
  public static final String PREREQUISITE_CD = "PRERQ";

  @Id
  @Basic(optional = false)
  @Column(name = "asgncntcd", nullable = false, length = 8)
  private String keywordCode;
  @Basic(optional = false)
  @Column(name = "description", nullable = false, length = 30)
  private String description;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "keywordType",fetch=FetchType.LAZY)
  private Collection<AssignmentKeyword> keywordCollection;

  public AssignmentKeywordType() {
  }

  public AssignmentKeywordType(String keywordCode) {
    this.keywordCode = keywordCode;
  }

  public AssignmentKeywordType(String keywordCode, String description) {
    this.keywordCode = keywordCode;
    this.description = description;
  }

  public String getKeywordCode() {
    return keywordCode;
  }

  public void setKeywordCode(String keywordCode) {
    this.keywordCode = keywordCode;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public Collection<AssignmentKeyword> getKeywordCollection() {
    return keywordCollection;
  }

  public void setKeywordCollection(Collection<AssignmentKeyword> keywordCollection) {
    this.keywordCollection = keywordCollection;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (keywordCode != null ? keywordCode.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentKeywordType)) {
      return false;
    }
    AssignmentKeywordType other = (AssignmentKeywordType) object;
    if ((this.keywordCode == null && other.keywordCode != null) || (this.keywordCode != null && !this.keywordCode.equals(other.keywordCode))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentKeywordType[keywordCode=" + keywordCode + "]";
  }

}
